package com.example.demo;

import com.example.demo.controller.UserController;
import com.example.demo.controller.UserController2;
import com.example.demo.controller.UserController3;
import com.example.demo.model.Student;
import com.example.demo.model.UserInfo;
import com.example.demo.properties.PropertiesController;
import com.example.demo.properties.Stu;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan("com.example.demo")
@SpringBootApplication
public class SpringBootIocApplication {

    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(SpringBootIocApplication.class, args);

//		UserController bean = context.getBean(UserController.class);
//		bean.sayHi();
        /**
         * 获取bean的三种方式
         * 1.通过名称来获取
         * 2.通过类型来获取
         * 3.通过类型+名称来获取
         */

//		UserController userController1 =(UserController) context.getBean("userController");
//		System.out.println(userController1);
//		userController1.sayHi();
//		UserController userController2 = context.getBean(UserController.class);
//		System.out.println(userController2);
//		userController2.sayHi();
//		UserController userController3 = context.getBean("userController", UserController.class);
//		System.out.println(userController3);
//		userController3.sayHi();

//		UserService bean = context.getBean(UserService.class);
//		bean.sayHi();

//		UserRepository bean = context.getBean(UserRepository.class);
//		bean.sayHi();

//		UserConfiguration bean = context.getBean(UserConfiguration.class);
//		bean.sayHi();

//		UserComponent bean = context.getBean(UserComponent.class);
//		bean.sayHi();

        /**
         * 方法注解Bean
         *
         */

//		UserInfo bean = context.getBean(UserInfo.class);
//		System.out.println(bean);

//        UserInfo user1 =(UserInfo) context.getBean("user1");
//        System.out.println(user1);
//
//        UserInfo user2 =(UserInfo) context.getBean("user2");
//        System.out.println(user2);

//        UserInfo user1 =(UserInfo) context.getBean("userName1");
//        System.out.println(user1);
//
//        UserInfo user2 =(UserInfo) context.getBean("userName2");
//        System.out.println(user2);
//
//        UserController2 uc2 = (UserController2)context.getBean("uc2");
//        System.out.println(uc2);
//        UserController bean = context.getBean(UserController.class);
//        bean.sayHi();


//        UserController3 bean = context.getBean(UserController3.class);
//        System.out.println(bean.getUserInfo());
//        PropertiesController bean = context.getBean(PropertiesController.class);
//        System.out.println(bean.getPort());
//        Stu bean1 = context.getBean(Stu.class);
//        System.out.println(bean1);

    }

}
